package generators;

import gamebackend.Block;

import java.util.Random;



public class BasicBlockGenerator extends AbstractRandomGenerator implements BlockGenerator {
	private BlockRule my_rule;
	public BasicBlockGenerator(final Block the_block, final BlockRule the_rule, final Random the_random, final double the_chance) {
		super(the_block, the_random, the_chance);
		my_rule = the_rule;
	}
	public BasicBlockGenerator(final Block the_block, final Block the_replaced, final Random the_random, final double the_chance) {
		this(the_block, new BlockRule(){

			@Override
			public boolean test(Block block) {
				// TODO Auto-generated method stub
				return block == the_replaced;
			}}, the_random, the_chance);
	}
	public void generate(Block[][] blocks) {
		final int row = blocks.length - 1;
		for (int col = 0; col < blocks[row].length; col++) {
			if (my_rule.test(blocks[row][col]) && getRandom().nextDouble() < getChance()) {
				blocks[row][col] = getBlock();
			}
		}
	}
	
}
